
//
//  Extension+UIImage.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/18.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit

extension UIImage {
    
    class func emoticonsImage(emoticonModel:ZYEmoticonModel) -> UIImage? {
        let png = emoticonModel.png ?? ""//需要拼接
        let path = emoticonModel.path ?? ""//这样才行   why？
        //从Bundle中取图的方式
        let img = UIImage(named: "\(path)\(png)", inBundle: ZYEmoticonTools.sharedTools.emoticonsBundle, compatibleWithTraitCollection: nil)
        return img
    }
    
    class func dealImageScale(image:UIImage, width:CGFloat) -> UIImage {
        
        if image.size.width < width {
            return image
        }
        //等比例 压缩
        let height = image.size.height * width/image.size.width
        
        let rect = CGRect(x: 0, y: 0, width: width, height: height)
        //MARK: - 压缩图片 - 绘图
        UIGraphicsBeginImageContext(rect.size)//01.开启上下文
        image.drawInRect(rect)//02.把内容 渲染到 图片上下文中
        let result = UIGraphicsGetImageFromCurrentImageContext()//03.从上下文获取内容
        UIGraphicsEndImageContext()//04.结束上下文
        
        return result
    }
    
    
    
}
